Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Component best practices- async flags check #73

Merged
merged 90 commits into from
May 29, 2024

Conversation

d3xter666
Copy link
Contributor

JIRA: CPOUI5FOUNDATION-792

@d3xter666 d3xter666 marked this pull request as draft April 16, 2024 09:08
@matz3 matz3 changed the title feat: Component best practices feat: Detect Component best practices Apr 17, 2024
@matz3 matz3 mentioned this pull request Apr 17, 2024
27 tasks
@d3xter666 d3xter666 force-pushed the component-best-practices branch from f14afdd to ea65aa3 Compare April 18, 2024 13:48
@d3xter666 d3xter666 requested a review from a team April 19, 2024 11:18
@d3xter666 d3xter666 marked this pull request as ready for review April 19, 2024 11:18
src/linter/ui5Types/SourceFileLinter.ts Outdated Show resolved Hide resolved
src/linter/ui5Types/SourceFileLinter.ts Outdated Show resolved Hide resolved
@d3xter666 d3xter666 marked this pull request as draft April 24, 2024 06:43
@d3xter666 d3xter666 marked this pull request as ready for review April 25, 2024 13:51
@d3xter666 d3xter666 requested review from matz3 and a team April 25, 2024 13:51
test/lib/linter/rules/snapshots/CSPCompliance.ts.md Outdated Show resolved Hide resolved
test/lib/linter/rules/snapshots/BestPractices.ts.md Outdated Show resolved Hide resolved
test/lib/linter/rules/snapshots/BestPractices.ts.md Outdated Show resolved Hide resolved
src/linter/ui5Types/BestPractices.ts Outdated Show resolved Hide resolved
src/linter/ui5Types/SourceFileLinter.ts Outdated Show resolved Hide resolved
src/linter/ui5Types/BestPractices.ts Outdated Show resolved Hide resolved
Copy link
Member

@matz3 matz3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see test cases for the other common base component classes in UI5:

  • sap/ui/generic/app/AppComponent
  • sap/suite/ui/generic/template/lib/AppComponent
  • sap/fe/core/AppComponent

@d3xter666
Copy link
Contributor Author

d3xter666 commented Apr 26, 2024

I don't see test cases for the other common base component classes in UI5:

sap/ui/generic/app/AppComponent
sap/suite/ui/generic/template/lib/AppComponent
sap/fe/core/AppComponent

These are all extending the sap/ui/core/UIComponent, so the general solution would handle them with the help of UI5 Types. Further more, if some of those classes starts implementing the async interface, that would also be matched :

const uiComponentImportVar = moduleImports.reduce((varName: string, importClause: ts.Node) => {

@d3xter666 d3xter666 force-pushed the component-best-practices branch from 66c09e8 to d60a47e Compare May 7, 2024 13:14
@d3xter666 d3xter666 requested review from a team and matz3 May 8, 2024 05:49
d3xter666 added a commit that referenced this pull request May 14, 2024
This change updates `@sapui5/types` to 1.120.13 which is vital for
#73
RandomByte and others added 6 commits May 28, 2024 11:34
Snapshots reflect unexpected behavior. Negative tests should have no
findings while positive tests should show findings.
…terface flag

Since the async interface is either used or not, the information whether
it is "not set" is redundant and the "parent property not set"
information is not applicable.
@d3xter666 d3xter666 changed the title feat: Detect Component best practices feat: Component best practices: async flags check May 28, 2024
@d3xter666 d3xter666 changed the title feat: Component best practices: async flags check feat: Component best practices- async flags check May 28, 2024
@d3xter666 d3xter666 requested review from RandomByte, flovogt and matz3 May 28, 2024 11:59
if (pathsToLint?.length) {
const absoluteFilePaths = resolveFilePaths(rootDir, pathsToLint);
resolvedFilePaths = transformFilePathsToVirtualPaths(
absoluteFilePaths, rootDir, "/", rootDir);
// Extract the (virtual) path from the filename
virBasePath = resolvedFilePaths[0].split("/").slice(0, -1).join("/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason for adae2ac ?

I'm wondering whether this approach still works if the first path in the array is deeply nested. For example /resources/my/app/controller/MyController.js would lead to virtual base path /resources/my/app/controller/. Which does not match for other paths like /resources/my/app/view/MyView.view.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for that change and the related ones is that for the test cases it used to read files one by one and didn't have the context for the parent components, for example.

The problem lies in the fact that without a /resource prefix, the files were not found. To be honest, I'm not sure for the core reason behnid this behaviour, but I guess it might be something with the Reader

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, you're right about the deeply nested components 🤔

But, how to extract the namespace without breaking the signature of the function?
Maybe, reuse the logic from lintProject(), but then we need a project, not a single file...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the commit and all tests are still green 😅

Copy link
Contributor Author

@d3xter666 d3xter666 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it’s not just that change 😅
I have tried several things to provide a better handling of those resources.

Maybe, directly comparing/reseting the file with the main branch would be easier 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, not sure I understand the implications...

I just pushed the revert which restores the behavior I think is better (and should work for deep paths). Let's discuss it based on that 👍

Copy link
Contributor Author

@d3xter666 d3xter666 May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look here: src/linter/linter.ts

This is the original change compared to the main branch.
The change is working pretty well, except that it cannot handle /test-resources/ and that's why I needed to find a better way of doing it.
Please take a look at the conversation we had with @flovogt on that matter here: https://github.com/SAP/ui5-linter/pull/73/files#r1601613818

But, if we take a look at the implementation of the lintProject() method, it again relies only on the /resources path, ignoring the /test-resources.

If this is ok, then we can leave it as it is now :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks. Since the lintFile API is currently only used in our tests, I think we can safely go with the current state and ignore the test-resources case for now 👍

src/linter/ui5Types/SourceFileLinter.ts Outdated Show resolved Hide resolved
src/linter/ui5Types/SourceFileLinter.ts Outdated Show resolved Hide resolved
src/linter/ui5Types/SourceFileLinter.ts Outdated Show resolved Hide resolved
src/linter/ui5Types/bestPractices.ts Outdated Show resolved Hide resolved
@RandomByte RandomByte force-pushed the component-best-practices branch from 108c6a2 to f136e64 Compare May 28, 2024 13:22
@RandomByte
Copy link
Member

I'm fine with this PR and once #73 (comment) is clarified we can merge it.

As a follow-up I would like us to extract the texts similar to https://github.com/SAP/ui5-linter/pull/112/files#diff-9d3ca30e9cd9e1355253f085c67fd2abafe4dfff649602cacf8b3ddef81db990 and hand them over to UA for review.

@RandomByte RandomByte force-pushed the component-best-practices branch from 8e42467 to f136e64 Compare May 28, 2024 20:28
@RandomByte
Copy link
Member

GitHub requires an additional review from someone other than me 😅 @flovogt

@d3xter666 d3xter666 merged commit 1c58105 into main May 29, 2024
29 checks passed
@d3xter666 d3xter666 deleted the component-best-practices branch May 29, 2024 07:31
@openui5bot openui5bot mentioned this pull request May 26, 2024
matz3 added a commit that referenced this pull request Aug 9, 2024
A CallExpression on a CallExpression wasn't handled yet and caused a
fatal error.

This commit also adds a test case for another issue that was already
fixed via #73 (SuperKeyword).

Fixes: #246
matz3 added a commit that referenced this pull request Aug 12, 2024
A CallExpression on a CallExpression wasn't handled yet and caused a
fatal error.

This commit also adds a test case for another issue that was already
fixed via #73 (SuperKeyword).

Fixes: #246
matz3 added a commit that referenced this pull request Aug 12, 2024
A CallExpression on a CallExpression wasn't handled yet and caused a
fatal error.

This commit also adds a test case for another issue that was already
fixed via #73 (SuperKeyword).

Fixes: #246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants